package com.example.demo.controller;
import javax.annotation.Resource;
import com.zengtengpeng.common.utils.ExcelUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.zengtengpeng.common.bean.DataRes;
import java.util.List;
import java.util.LinkedHashMap;
import java.util.Map;
import org.springframework.stereotype.Controller;
import io.swagger.annotations.ApiOperation;
import com.example.demo.bean.QrtzCalendars;
import com.example.demo.service.QrtzCalendarsService;


/**
 *qrtz_calendars controller
 */
@Controller
public class QrtzCalendarsController  {


	@Resource
	private QrtzCalendarsService qrtzCalendarsService;
	/**
	 * 删除-qrtz_calendars
	 */
	@ResponseBody
	@RequestMapping("qrtzCalendars/deleteByPrimaryKey")
	@ApiOperation(value="根据主键删除", notes="参数只用到了主键id,其他参数忽略" ,httpMethod="POST")
	public DataRes deleteByPrimaryKey(QrtzCalendars qrtzCalendars,HttpServletRequest request,HttpServletResponse response){
		return DataRes.success(qrtzCalendarsService.deleteByPrimaryKey(qrtzCalendars));
	}


	/**
	 *  保存 (主键为空则增加否则修改)-> qrtz_calendars
	 */
	@ResponseBody
	@RequestMapping("qrtzCalendars/save")
	@ApiOperation(value="保存", notes="主键为空则增加否则修改" ,httpMethod="POST")
	public DataRes save(QrtzCalendars qrtzCalendars,HttpServletRequest request,HttpServletResponse response){
		if(qrtzCalendars.getCalendarName()==null){
			return DataRes.success(qrtzCalendarsService.insert(qrtzCalendars));
		}
		return DataRes.success(qrtzCalendarsService.update(qrtzCalendars));

	}


	/**
	 * 根据主键查询->qrtz_calendars
	 */
	@ResponseBody
	@RequestMapping("qrtzCalendars/selectByPrimaryKey")
	@ApiOperation(value="根据主键查询", notes="参数只用到了主键." ,httpMethod="POST")
	public DataRes selectByPrimaryKey(QrtzCalendars qrtzCalendars,HttpServletRequest request,HttpServletResponse response){
		return DataRes.success(qrtzCalendarsService.selectByPrimaryKey(qrtzCalendars));
	}


	/**
	 * 根据条件查询(所有的实体属性都是条件,如果为空则忽略该字段)->qrtz_calendars
	 */
	@ResponseBody
	@RequestMapping("qrtzCalendars/selectByCondition")
	@ApiOperation(value="根据条件查询", notes="参数为空则忽略." ,httpMethod="POST")
	public DataRes selectByCondition(QrtzCalendars qrtzCalendars,HttpServletRequest request,HttpServletResponse response){
		return DataRes.success(qrtzCalendarsService.selectByCondition(qrtzCalendars));
	}


	/**
	 * 分页查询 (所有的实体属性都是条件,如果为空则忽略该字段) (详见Page类.所以的实体都继承该类 默认 page=1 pageSize=10)->qrtz_calendars
	 */
	@ResponseBody
	@RequestMapping("qrtzCalendars/selectAllByPaging")
	@ApiOperation(value="分页查询", notes="默认page=1pageSize等于10详见Page类(所有bean都继承该类).参数为空则忽略" ,httpMethod="POST")
	public DataRes selectAllByPaging(QrtzCalendars qrtzCalendars,HttpServletRequest request,HttpServletResponse response){
		return DataRes.success(qrtzCalendarsService.selectAllByPaging(qrtzCalendars));
	}


	/**
	 * 导出报表->qrtz_calendars
	 */
	@RequestMapping("qrtzCalendars/export")
	@ApiOperation(value="导出excel", notes="导出全部数据.参数为空则忽略." ,httpMethod="POST")
	public void export(QrtzCalendars qrtzCalendars,HttpServletRequest request,HttpServletResponse response){
		List<QrtzCalendars> list= qrtzCalendarsService.selectAll(qrtzCalendars);
		Map<String, String> header = new LinkedHashMap<>();
		header.put("schedName", "sched_name");
		header.put("calendarName", "calendar_name");
		header.put("calendar", "calendar");
		ExcelUtils.exportExcel("qrtz_calendars",header,list,response,request);

	}


}
